/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package src;

import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Locale;

/*Tato třída bude nést parametry evidovaného žáka*/
/**
 *
 * @author Viktor
 */

public class Zak implements Serializable, Comparable<Zak> {
transient Collator collator;
private String prijmeni;
private String jmeno;
//private int ID;

private String telefon;
private String datNar;
private String bydliste;

//public int[] mesice;
//
//public int[] dochazka;

    ArrayList<Krouzek> krouzky;

public int[][] pole;

private int[] leden;
private int[] unor;
private int[] brezen;
private int[] duben;
private int[] kveten;
private int[] cerven;
private int[] cervenec;
private int[] srpen;
private int[] zari;
private int[] rijen;
private int[] listopad;
private int[] prosinec;
private int[] unorP;

   
public Zak(String prijmeni, String jmeno, String telefon, String datNar, String bydliste) {
        this.prijmeni = prijmeni;
        this.jmeno = jmeno;
        this.telefon = telefon;
        this.datNar = datNar;
        this.bydliste = bydliste;
        krouzky = new ArrayList<Krouzek> ();
        collator = Collator.getInstance(new Locale("cs","CZ"));
      
//        pole = new int[][]{
//            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
//        };
      //  mesice = new int[12];
//        spoj2();
        initpole();
       
    }

    private void spoj() {
        for(int i = 0; i < 12; i++){
            switch(i){
  /*leden*/     case 0: pole[i] = new int[31]; break;
                case 1: pole[i] = new int[28]; break;/*osetrit prestupny rok*/
                case 2: pole[i] = new int[31]; break;
                case 3: pole[i] = new int[30]; break;  
                case 4: pole[i] = new int[31]; break;
                case 5: pole[i] = new int[ 30]; break;
                case 6: pole[i] = new int[31]; break;
                case 7: pole[i] = new int[31]; break;
                case 8: pole[i] = new int[30]; break;    
                case 9: pole[i] = new int[31]; break;    
                case 10: pole[i] = new int[30]; break;    
   /*Prosinec*/ case 11: pole[i] = new int[31]; break;    
        }
        }
    }
    
    private void spoj2(){
         pole = new int[][]{
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },//28
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//30
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//30 
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//30
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//30
            {0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//31
            
        };
    }
    
    public void prisel(int mesic, int den){
        pole[mesic][den] = 1;
    }
    
    public void prisel2(int mesic, int den){
        int[] pompole = zpristupniMesic(mesic);
        if(pompole !=null){
            pompole[den] = 1;
        }
    }

    public ArrayList<Krouzek> getKrouzky() {
        return krouzky;
    }
    
   
    public void priradKrouzek(Krouzek k){
        krouzky.add(k);
    }

//    public double dochazkaProc(int mesic){
//        double sumpritomen = 0;
//        for(int i = 0;i < pole[mesic].length; i++){
//            if(pole[mesic][i] == 1){
//                sumpritomen++;
//            }
//        }
//        return sumpritomen/pole[mesic].length * 100;
//    }
    
    public double dochazkaProc(int mesic){
        double sumpritomen = 0;
       
       int[] pompole =  zpristupniMesic(mesic);
        for(int i = 0; i < pompole.length;i++){
            if(pompole[i] == 1){
                sumpritomen++;
            }
        }
        
        return sumpritomen/pompole.length * 100;
    }

    public String getBydliste() {
        return bydliste;
    }

    public String getDatNar() {
        return datNar;
    }

    public String getJmeno() {
        return jmeno;
    }

    public int[][] getPole() {
        return pole;
    }

    public String getPrijmeni() {
        return prijmeni;
    }

    public String getTelefon() {
        return telefon;
    }

    private void initpole() {
     leden = new int[31];
unor = new int[28];
brezen = new int[31];
duben = new int[30];
kveten = new int[31];
cerven = new int[30];
cervenec = new int[31];
srpen = new int[31];
zari = new int[30];
rijen = new int[31];
listopad = new int[30];
prosinec = new int[31];
unorP = new int[29];
    }

    public int[] zpristupniMesic(int mesic){
         switch(mesic){
            case 0: return leden;
            case 1: return unor;
            case 2: return brezen;
            case 3: return duben;
            case 4: return kveten;
            case 5: return cerven;
            case 6: return cervenec;
            case 7: return srpen;
            case 8: return zari;
            case 9: return rijen;
            case 10: return listopad;
            case 11: return prosinec;
            case 12: return unorP;
            default : return null;
        }
    }

  public int compareTo(Zak o) {
     //return getPrijmeni().compareTo(o.getPrijmeni());
      return collator.compare(getPrijmeni(),o.getPrijmeni() );
    }
}
